package com.xjy.headfirst.迭代器;

import org.apache.commons.lang3.ObjectUtils;

import java.util.ArrayList;

/**
 * decription:
 *
 * @author 辛纪元
 * @since 2022-07-15
 */

public class PancakeHouseMenuIterator implements Iterator {

    ArrayList<MenuItem> menuItems;

    int position;

    public PancakeHouseMenuIterator(ArrayList<MenuItem> menuItems) {
        this.menuItems = menuItems;
    }

    void addItem(String name, String description, boolean vegetarian, double price) {
        MenuItem menuItem = new MenuItem(name, description, vegetarian, price);
        menuItems.add(menuItem);
    }

    @Override
    public boolean hasNext() {
        return menuItems.size() > position;
    }

    @Override
    public Object next() {
        MenuItem menuItem = menuItems.get(position);
        position = position + 1;
        return menuItem;
    }
}
